import App from "./App.vue";
import plugins from "./plugins";
import store from "./store";
import uviewPlus from "uview-plus";
import { createPinia } from "pinia";

// 国际化
import i18n from "@/lang";

import { createSSRApp } from "vue";
import directive from "./directive"; // directive

import { useDict } from "@/utils/dict";
import {
  parseTime,
  resetForm,
  addDateRange,
  handleTree,
  selectDictLabel,
  selectDictLabels,
} from "@/utils/ruoyi";

const pinia = createPinia();
export function createApp() {
  const app = createSSRApp(App);

  // app.use(pinia);
  app.use(store);
  app.use(uviewPlus);
  app.use(plugins);
  app.use(i18n);
  directive(app);

  // 由于微信小程序的运行机制问题，需声明如下一行，H5和APP非必填
  app.config.globalProperties._i18n = i18n;

  // 全局方法挂载
  app.config.globalProperties.useDict = useDict;
  app.config.globalProperties.parseTime = parseTime;
  app.config.globalProperties.resetForm = resetForm;
  app.config.globalProperties.handleTree = handleTree;
  app.config.globalProperties.addDateRange = addDateRange;
  app.config.globalProperties.selectDictLabel = selectDictLabel;
  app.config.globalProperties.selectDictLabels = selectDictLabels;

  return {
    app,
  };
}
